const UserDataManager = {

  loadUserData () {
    let _userData = localStorage.getItem('userData')
    if (_userData) {
      this._userData = JSON.parse(_userData)
    } else {
      this._userData = {
        newUser: true,
        chapterLevel: 0,
        carLevel: 4,
        dollar: 0
      }
    }
    // this._userData.chapterLevel = 3
    // this._userData.carLevel = 40
    // this._userData.dollar = 0
  },

  getUserData () {
    return this._userData
  },

  saveUserData (userData) {
    this._userData = userData
    localStorage.setItem('userData', JSON.stringify(userData))
  },

  saveUserData2 (key, val) {
    this._userData[key] = val
    localStorage.setItem('userData', JSON.stringify(this._userData))
  }
}

module.exports = UserDataManager
